home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / pd_bisection.pro < prev    next >
Text File  |  1997-07-08  |  1KB  |  43 lines

  1. ; $Id: pd_bisection.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ;  Copyright (c) 1991-1997, Research Systems Inc.  All rights
  4. ;  reserved. Unauthorized reproduction prohibited.
  5.  
  6.  
  7.  
  8. function pd_bisection, a, funct, U, L, del
  9. ; pd_bisections uses a simple bisection technique on probabilty
  10. ; distribution funct to find the cutoff point x so that the probabilty of
  11. ; an observation from the given distribution less than x is a(0). U and L are
  12. ; respectively upper and lower limits for x. a(1) and a(2) are df`s if
  13. ; appropriate. Funct is a string.
  14.  
  15.  SA = size(a)
  16.  
  17.  if (N_Elements(del) EQ 0) then del =.000001
  18.  p = a(0)
  19.  if (p LT 0 or p GT 1) then return, -1
  20.  
  21.  Up = U
  22.  Low = L
  23.  Mid = L + (U-L)*p
  24.  count = 1
  25.  
  26.  while (abs(up - low) GT del*mid) and (count lt 100) DO BEGIN
  27.    if n_elements(z) ge 1 then begin    ;1st time?
  28.     if z GT p then  Up = Mid else Low = Mid
  29.     Mid = (Up + Low) /2.
  30.     endif
  31.    case n_elements(a) of
  32.     1: z = call_function(funct, mid)
  33.     2: z = call_function(funct, mid, a(1))
  34.     3: z = call_function(funct, mid, a(1), a(2))
  35.     else: return, -1
  36.     ENDCASE
  37.   count = count + 1
  38.  endwhile
  39.  return,Mid
  40. END
  41.  
  42.  
  43.